Excel VBA for Complete Beginners: A Home and Learn Book by Carney Ken
Author:Carney, Ken [Carney, Ken]
Language: eng
Format: azw3, epub
Published: 2020-05-16T16:00:00+00:00
Each variable is separated by a comma. You can pass no variables, one variable, or as many as you need.
As well as specifying the variable names, you can specify a variable type, as well:
Sub SecondCode(BoldValue As Boolean, NameValue As String)
End Sub
If you miss out the "As Variable_Type" then the variables are treated As Variant . Notice that you don't need the Dim word anymore.
But this is just setting up the variable. They have nothing in them yet. To place something in these variables, you do so on the calling line.
Call SecondCode(True, "Arial")
Each value you place between the round brackets is known as an argument (or sometimes a parameter). The arguments must match. So if you have set up your Sub line to accept two arguments then you must pass two arguments in on the calling line, otherwise you'll get an error. The order of the arguments must match, as well. If the first variable is a Boolean, then you can't pass in a value of "Arial". Likewise, if the second argument is a String, then you can't pass in a number. Unless, that is, you set each variable up as Variants by missing off As String , As Boolean between the round brackets of the Sub line.
To clear that up, if our Sub is this:
Sub SecondCode(BoldValue As Boolean, NameValue As String)
Then this Calling line will get you an error:
Call SecondCode("value", "Arial")
But this won't
Call SecondCode(True, "Arial")
The error is because we have the text "value" as the first argument. The Sub says that BoldValue should be a Boolean, however. Boolean values can either be True or False , so VBA will give you a "Type Mismatch" error. (You can have 1 or 0 for your Booleans, though. A value of 1 means True and a value of 0 means False. You can even put the True and False in quote marks, and in any case you like: upper, lower, or a mix.)
In the Sub where your calling line is, you can set up variables, place values in the variables, and then type the variable names between the round brackets. Like this:
Dim boolValue As Boolean
Dim strText As String
boolValue = True
strText = "Arial"
Call SecondCode( boolValue, strText )
Now, we have variable names between the round brackets of the calling line. VBA will pass over to the SecondCode Sub whatever is inside of these variables. It will transfer the values to the new variables names:
Sub SecondCode(BoldValue As Boolean, NameValue As String)
So the value in boolValue will get transferred to the BoldValue variable, and the value in strText will get transferred to the NameValue variable.
Once you have values in the new variables between the round brackets of your Sub, you can do something with these variables.
To see how that works, let's now amend our SecondCode Sub to accept variables.
Change the first line of your code to this (all on oneline):
Private Sub SecondCode(BoldValue As Boolean, NameValue As String, SizeValue)
Here, we've set three arguments between the round brackets of SecondCode . The first is a Boolean value called BoldValue , and the second is a String value called NameValue .
Download
Excel VBA for Complete Beginners: A Home and Learn Book by Carney Ken.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
NET | C & C++ Windows Programming |
SQL Server | VBA |
Visual Basic |
Deep Learning with Python by François Chollet(11922)
Hello! Python by Anthony Briggs(9388)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9353)
The Mikado Method by Ola Ellnestam Daniel Brolund(9321)
Dependency Injection in .NET by Mark Seemann(8867)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7860)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7352)
Grails in Action by Glen Smith Peter Ledbrook(7305)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7127)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5969)
Kotlin in Action by Dmitry Jemerov(4654)
Practical Vim (for Kathryn Amaral) by Drew Neil(3734)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(3602)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3452)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3253)
Learning Java by Patrick Niemeyer & Daniel Leuck(2875)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2847)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(2847)
Microservices with Go by Alexander Shuiskov(2642)